package dao

import models.Tables._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import javax.inject.Inject
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

/**
 * Created by yz on 2018/7/17
 */
class UserNameDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends
  HasDatabaseConfigProvider[JdbcProfile] {

  import profile.api._

  type MyRow = UserNameRow
  val table = UserName

  def selectAll = db.run(table.result)

  def insert(row: MyRow): Future[Unit] = db.run(table += row).map(_ => ())

  def deleteById(id: Int): Future[Unit] = db.run(table.filter(_.userId === id).delete).map(_ => ())


}
